<template>
  <el-aside width="200px"
            style="height:100%">
    <el-menu default-active="1"
             class="sidebar-el-menu"
             background-color="#242f42"
             text-color="#fff"
             active-text-color="#ffd04b">
      <el-sub-menu index="1"
                   v-if="authority.userManage">
        <template #title>
          <el-icon>
            <User />
          </el-icon>
          用户管理
        </template>
        <el-menu-item index="1-1"
                      @click="goUser()"
                      v-if="authority.admainManage">
          管理员管理
        </el-menu-item>
        <el-menu-item index="1-2"
                      v-if="authority.authorityManage"
                      @click="toAuthority()">
          权限管理
        </el-menu-item>
        <el-menu-item index="1-3"
                      @click="toUser()"
                      v-if="authority.umsUserManage">
          客户管理
        </el-menu-item>
        <el-menu-item index="1-4"
                      v-if="authority.addressManage"
                      @click="toAddress()">
          地址管理
        </el-menu-item>
      </el-sub-menu>

      <el-sub-menu index="2"
                   v-if="authority.productManage">
        <template #title>
          <el-icon>
            <Goods />
          </el-icon>
          商品管理
        </template>
        <el-menu-item index="2-1"
                      v-if="authority.catoryManage"
                      @click="toProductCategory()">
          商品类别管理
        </el-menu-item>
        <el-menu-item index="2-2"
                      v-if="authority.brandManage"
                      @click="toProductBrandCatelog()">
          品牌管理
        </el-menu-item>
        <el-menu-item index="2-3"
                      v-if="authority.spuInfoManage"
                      @click="toProductSpuInfoCatelog()">
          Spu管理
        </el-menu-item>
        <el-menu-item index="2-4"
                      v-if="authority.attrGroupManage"
                      @click="toProductAttrGroup()">
          属性组管理
        </el-menu-item>
      </el-sub-menu>

      <el-sub-menu index="3"
                   v-if="authority.orderManage">
        <template #title>
          <el-icon>
            <Notebook />
          </el-icon>
          订单管理
        </template>
        <el-menu-item index="3-1"
                      @click="toOrder()"
                      v-if="authority.orderInfoManage">
          订单信息管理
        </el-menu-item>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: "Aside",
  data () {
    return {
      authority: {
        userManage: false,
        admainManage: false,
        authorityManage: false,
        addressManage:false,
        productManage: false,
        catoryManage: false,
        brandManage: false,
        spuInfoManage:false,
        attrGroupManage:false,
        orderManage:false,
        orderInfoManage:false,
        umsUserManage:true,
      }
    }
  },
  created () {
    this.initAuthority()
    console.log(this.$store.state.authority)
  },
  methods: {
    initAuthority () {
      this.authority.userManage = this.$store.state.authority[this.$power.map.get("用户管理").property]
      this.authority.admainManage = this.$store.state.authority[this.$power.map.get("用户管理-管理员管理").property]
      this.authority.authorityManage = this.$store.state.authority[this.$power.map.get("用户管理-权限管理").property]
      this.authority.addressManage = this.$store.state.authority[this.$power.map.get("用户管理-地址管理").property]
      this.authority.productManage = this.$store.state.authority[this.$power.map.get("商品管理").property]
      this.authority.catoryManage = this.$store.state.authority[this.$power.map.get("商品管理-类别管理").property]
      this.authority.brandManage = this.$store.state.authority[this.$power.map.get("商品管理-品牌管理").property]
      this.authority.spuInfoManage = this.$store.state.authority[this.$power.map.get("商品管理-Spu管理").property]
      this.authority.attrGroupManage = this.$store.state.authority[this.$power.map.get("商品管理-属性组管理").property]
      this.authority.orderManage = this.$store.state.authority[this.$power.map.get("订单管理").property]
      this.authority.orderInfoManage = this.$store.state.authority[this.$power.map.get("订单管理-订单信息管理").property]
      Object.freeze(this.authority)
    },
    toProductCategory () {
      this.$router.push({ path: '/main/product/category' })
    },
    toProductBrandCatelog () {
      this.$router.push({ path: '/main/product/brand' })
    },
    toProductSpuInfoCatelog () {
      this.$router.push({ path: '/main/product/spuinfo'})
    },
    goUser () {
      this.$router.push({ path: '/admin/user' })
    },
    toAuthority () {
      this.$router.push({ path: '/main/admin/authority' })
    },
    toAddress () {
      this.$router.push({ path: '/main/user/address' })
    },
    toProductAttrGroup(){
      this.$router.push({ path: '/main/product/attributeGroup' })
    },
    toOrder(){
      this.$router.push({ path: '/main/order/order' })
    },
    toUser() {
      this.$router.push({ path: '/main/user/umsuser'})
    }
  }
}
</script>

<style scoped>
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 200px;
  height: 100%;
}
</style>


